<template>
    <div style="width:100%;height:100%;overflow:hidden">
        <weui-input :list="input_0_list" title="" :show_more="false" :tips="null" agreement_name="" more_label="" @on-change="on_input_0_change">
        </weui-input>
        <weui-cell :list="cell_0_list">
        </weui-cell>
    </div>
</template>

<script>
    import WeuiInput from '../vue2componentSet/src/components/WeuiInput'
    import WeuiCell from '../vue2componentSet/src/components/WeuiCell'
    import global from '../lib/global'
    import axios from 'axios'

    export default {
        components: {
            WeuiInput,
            WeuiCell
        },
        data() {
            return {
                input_0_list: [{
                    type: 'radio',
                    value: '',
                    list: [{
                        label: '微信红包',
                        value: 'wechat'
                    }, {
                        label: '支付宝',
                        value: 'alipay'
                    }]
                }],
                cell_0_list: [{
                    value: '绑定支付宝',
                    link: '#/bindAlipay'
                }]
            }
        },
        mounted() {
            this.$store.commit('set_title', '设置返现方式')

            if (!this.$store.state.customer) {
                this.$router.goback()
                return
            }

            this.$set(this.input_0_list[0], 'value', this.$store.state.customer.returnWay)
        },
        methods: {
            on_input_0_change() {
                if (this.input_0_list[0].value == 'alipay') {
                    if (!this.$store.state.customer.alipay) {
                        this.$store.commit('toast', {
                            type: 'warn',
                            content: '请先绑定支付宝'
                        })
                        return
                    }
                }
                axios.post(global.server + 'setReturnWay.do', {
                    returnWay: this.input_0_list[0].value
                }).then(result => {
                    this.$store.state.customer.returnWay = this.input_0_list[0].value
                    this.$router.goback()
                })
            }
        },
    }
</script>
